package com.jwork.progress.service;

import com.jwork.progress.params.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;

@Service
public class AsyncTaskService {
    @Autowired
    private RequestAsyncTaskService requestAsyncTaskService;

    public CommonResponse getTaskWork() throws InterruptedException {
        long start = System.currentTimeMillis();
        CountDownLatch countDownLatch = new CountDownLatch(7);
        requestAsyncTaskService.task1(countDownLatch);
        requestAsyncTaskService.task2(countDownLatch);
        requestAsyncTaskService.task3(countDownLatch);
        requestAsyncTaskService.task4(countDownLatch);
        requestAsyncTaskService.task5(countDownLatch);
        requestAsyncTaskService.task6(countDownLatch);
        requestAsyncTaskService.task7(countDownLatch);

        countDownLatch.await();
        long end = System.currentTimeMillis();
        long l = end - start;
        return CommonResponse.success("成功！" + l);
    }
}
